<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <th:block th:include="include :: select2-css" />
    <title>关联流程</title>
</head>
<body>
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-leave-add" style="display: none;">
        <input type="hidden" name="nodes" />
        <div class="form-group">
            <div class="col-sm-8">
                <select id="selectNodes" class="form-control m-b select2-multiple">
                    <option th:each="node,nodeState:${nodes}" th:value="${nodeState.index}" th:text="${node.name}"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var prefix = "/process";
    var nodes = [[${nodes}]];
    // 防止 select2 渲染延迟
    setTimeout(function () {
        $('#form-leave-add').css('display', '');
    }, 100);

    $("#form-leave-add").validate({
        focusCleanup: true
    });
    function submitHandler() {
        var formId = [[${formId}]];
        var index = $('#selectNodes').select2('val');
        var node = nodes[index];
        var data = {
            processDefinitionId:node.id,
            formId:formId
        };
        $.modal.confirm("确认要提交申请吗?", function() {
            var url = prefix + "/linkProcess";
            $.operate.save(url, data);
        });
    }
</script>
</body>
</html>